<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: showplayground.php 1126 2008-06-09 05:45:04Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 
  function showPlayground($pgid, &$overall_config) {
    global $joomleague, $mainframe, $jlgConfig;
    global $htmlHelper;
    
		$showPG_config=$joomleague->getTemplateConfig("show_playground.tpl");
		
    $playground=new Playground($joomleague->_db);
		$playground->load($pgid);
		
		if ($playground->country) {
			$countrycode=explode("_", _JL_LOCALE);
	   	$joomleague->_db->setQuery( "SELECT countries_name, countries_localname, countries_iso_code_2, countries_iso_code_3 FROM #__joomleague_countries WHERE countries_id=$playground->country");
	    $result = $joomleague->_db->loadObjectList();
	   	$countryname=$result[0]->countries_name;
	    if (isset($result[0]->countries_iso_code_3)) $countryname=$result[0]->countries_iso_code_3;
			if (strtoupper($result[0]->countries_iso_code_2)!=strtoupper($countrycode[0])) $countryname.=" (".$result[0]->countries_localname.")";
		}
		else $countryname="";
    
		// now get all teams which belongs to this playground (TODO: check published state of projects/seasons!!)
    $query = sprintf("SELECT team_id, project_id
                        FROM #__joomleague_team_joomleague
                       WHERE standard_playground = %s", $pgid);
    $joomleague->_db->setQuery($query);
    // TODO: put result with this project ID first!!
    $rows = $joomleague->_db->loadObjectList();
    $newrows=array();
		for ($x=0;$x<count($rows);$x++) {
			$row=&$rows[$x];
			$newrows[$row->project_id]->team_id[]=$row->team_id;
			$query="SELECT name, short_name, description FROM #__joomleague_teams WHERE id=$row->team_id";
			$joomleague->_db->setQuery($query);
			$newrows[$row->project_id]->teaminfos[$row->team_id] = $joomleague->_db->loadObjectList();
			$query="SELECT name FROM #__joomleague WHERE id=$row->project_id";
			$joomleague->_db->setQuery($query);
			$newrows[$row->project_id]->project_name = $joomleague->_db->loadResult();
		}
		
		$show_map = false;
	$address_string = $playground->address.", ".$playground->zip." ".$playground->city;

	// setup google map
  if (isset($overall_config['google_api_key']) && $overall_config['google_api_key'] != '' &&
    isset($showPG_config['show_map']) && $showPG_config['show_map'] == 1 && trim($address_string) != '') {
      $show_map = true;
      $map_config=$joomleague->getTemplateConfig("map.tpl");
	    $gm = new EasyGoogleMap($overall_config['google_api_key'], 'jl_pg_map');
	    $width = (is_int($map_config['width'])) ? $map_config['width'].'px' : $map_config['width'];
		  $gm->SetMapWidth($map_config['width']);
		  $gm->SetMapHeight($map_config['height']); 
		  $gm->SetMapControl($map_config['map_control']);
		  $gm->SetMapDefaultType($map_config['default_map_type']);
		  if (intval($map_config['map_zoom'])>0) $gm->SetMapZoom(intval($map_config['map_zoom']));
		  $gm->mScale = (intval($map_config['map_scale'])>0) ? TRUE : FALSE;
		  $gm->mMapType = (intval($map_config['map_type_select'])>0) ? TRUE : FALSE;
		
		  $gm->mContinuousZoom = (intval($map_config['cont_zoom'])>0) ? TRUE : FALSE;
		  $gm->mDoubleClickZoom = (intval($map_config['dblclick_zoom'])>0) ? TRUE : FALSE;
		  $gm->mInset = (intval($map_config['map_inset'])>0) ? TRUE : FALSE;
		
		  $gm->mShowMarker = (intval($map_config['show_marker'])>0) ? TRUE : FALSE;
		  $gm->SetMarkerIconStyle($map_config['map_icon_style']);
		  $gm->SetMarkerIconColor($map_config['map_icon_color']);
		  $gm->SetAddress($address_string);
	}
		require(getTemplateFile(JL_TEMPLATE_PATH, 'show_playground.tpl.php')); 

  }
  
?>